"""
统计数据模型
"""
from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field
from datetime import datetime


class UserStats(BaseModel):
    """用户统计数据"""
    user_id: str
    total_projects: int = 0
    active_projects: int = 0
    completed_projects: int = 0
    total_tasks: int = 0
    completed_tasks: int = 0
    in_progress_tasks: int = 0
    overdue_tasks: int = 0
    total_work_hours: float = 0.0
    this_month_hours: float = 0.0
    this_week_hours: float = 0.0
    avg_task_completion_time: float = 0.0
    task_completion_rate: float = 0.0
    on_time_completion_rate: float = 0.0


class ProjectSummary(BaseModel):
    """项目摘要"""
    id: str
    name: str
    status: str
    progress: float = 0.0
    created_at: Optional[datetime] = None


class TaskSummary(BaseModel):
    """任务摘要"""
    id: str
    title: str
    status: str
    priority: str
    due_date: Optional[datetime] = None
    created_at: Optional[datetime] = None


class WorkHourTrend(BaseModel):
    """工时趋势数据"""
    date: str
    hours: float = 0.0


class UserStatsResponse(BaseModel):
    """用户统计响应"""
    user_stats: UserStats
    recent_projects: List[ProjectSummary] = Field(default_factory=list)
    recent_tasks: List[TaskSummary] = Field(default_factory=list)
    work_hour_trend: List[WorkHourTrend] = Field(default_factory=list)


class DashboardStats(BaseModel):
    """仪表盘统计数据"""
    total_projects: int = 0
    active_projects: int = 0
    total_tasks: int = 0
    completed_tasks: int = 0
    pending_tasks: int = 0
    overdue_tasks: int = 0
    total_work_hours: float = 0.0
    this_month_hours: float = 0.0
    productivity_score: float = 0.0
    completion_rate: float = 0.0


class ProjectStats(BaseModel):
    """项目统计"""
    total_projects: int = 0
    active_projects: int = 0
    completed_projects: int = 0
    planning_projects: int = 0
    on_hold_projects: int = 0


class TaskStats(BaseModel):
    """任务统计"""
    total_tasks: int = 0
    pending_tasks: int = 0
    in_progress_tasks: int = 0
    completed_tasks: int = 0
    overdue_tasks: int = 0


class DefectStats(BaseModel):
    """缺陷统计"""
    total_defects: int = 0
    open_defects: int = 0
    resolved_defects: int = 0
    closed_defects: int = 0


class RequirementStats(BaseModel):
    """需求统计"""
    total_requirements: int = 0
    planning_requirements: int = 0
    active_requirements: int = 0
    completed_requirements: int = 0


class VersionStats(BaseModel):
    """版本统计"""
    total_versions: int = 0
    active_versions: int = 0
    released_versions: int = 0


class UserStatsSummary(BaseModel):
    """用户统计摘要"""
    total_users: int = 0
    active_users: int = 0
    inactive_users: int = 0


class DashboardOverviewResponse(BaseModel):
    """仪表盘概览响应"""
    project_stats: ProjectStats
    task_stats: TaskStats
    my_task_stats: TaskStats
    defect_stats: DefectStats
    requirement_stats: RequirementStats
    version_stats: VersionStats
    user_stats: UserStatsSummary